const multer  = require('multer')
const md5 = require("js-md5")
const storage = multer.diskStorage({
  destination: function (req, file, cb) {
    cb(null, 'upload/image')
  },

  filename: function (req, file, cb) {
    const fileExtension = file.originalname.split('.').pop()
    const fileName = md5(new Date().toString()) + '.' + fileExtension
    cb(null, fileName)
  }
})

const upload = multer({ 
  storage: storage,
  fileFilter: function (req, file, cb) {
      cb(null, true)
  }
 })

module.exports = {
  upload
}
